﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace proj2
{
    public partial class folderDialog : Form
    {
        private int _dirCount;
        private string[] _directories;
        private string[] _files;
        private string _path;

        public folderDialog()
        {
            InitializeComponent();
        }

        public string[] files
        {
            get { return _files; }
        }

        public string[] directories
        {
            get { return _directories; }
        }

        public string path
        {
            get { return _path; }
        }

        public int dirCount
        {
            get { return _dirCount; }
        }

        public bool checkBoxState
        {
            get { return subDirCheckBox.Checked; }
        }

        private void browseButton_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                int i = 0;
                pathTextBox.Text = folderBrowserDialog.SelectedPath;
                _path = pathTextBox.Text;
                string[] images = Directory.GetFiles(@pathTextBox.Text, "*.*");
                _directories = pathTextBox.Text.Split('\\');
                _files = new string[images.Length];
                foreach (string s in images)
                {
                    _files[i++] = s.Substring(s.LastIndexOf('\\'));
                }
                _dirCount = _files.Length;
            }
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(pathTextBox.Text))
            {

                errorProvider.SetError(pathTextBox, "Podaj ścieżkę do katalogu");
                errorProvider.SetIconAlignment(this.pathTextBox, ErrorIconAlignment.MiddleLeft);

                return;
            }
            else
                this.DialogResult = DialogResult.OK;
        }

        private void pathTextBox_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(pathTextBox.Text))
            {
                errorProvider.SetError(pathTextBox, "Podaj ścieżkę do katalogu");
                errorProvider.SetIconAlignment(this.pathTextBox, ErrorIconAlignment.MiddleLeft);

                return;
            }
            errorProvider.Clear();
        }

        private void pathTextBox_Validated(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(pathTextBox.Text) && this.DialogResult == DialogResult.OK)
            {

                errorProvider.SetError(pathTextBox, "Podaj ścieżkę do katalogu");
                errorProvider.SetIconAlignment(this.pathTextBox, ErrorIconAlignment.MiddleLeft);

                return;
            }
            errorProvider.Clear();

        }

    }
}
